#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<list>
#include<cstdlib>
#include<cmath>
#include<sstream>
#include<numeric>
#include<cstdio>
#include<cstring>
#include<stack>
#define PI acos(-1)
#define MP make_pair
#define PB push_back
#define VI vector <int>
#define PII pair <int,int>
#define LL long long
#define SET(v,i) memset(v, i, sizeof(v))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for (int i = (a); i >= (b); i--)
#define FORN(i,a,b) for (int i = (a); i < (b); i++)
#define DOWN(i,a,b) for (int i = (a); i > (b); i--)
#define FIT(it,v) for (typeof(v.begin()) it = v.begin(); it != v.end(); it++)
#define FITD(it,v) for (typeof(v.rbegin()) it = v.rbegin(); it != v.rend(); it++)
using namespace std;
bool is_prime(int k){
	for(int i=2;i*i<=k;i++)if(k%i==0)return false;
	return true;
	}
//cal all i<=x that k is the min prime factor of i  
int slove(int x,int k){
	if(x<k||!is_prime(k))return 0;
	int ans=x/k;
	for(int i=2;i<k&&i<=x/k;i++)ans-=slove(x/k,i);
	return ans;
	}
int main(){
	int a,b,k;
	while(cin>>a>>b>>k){
		cout<<slove(b,k)-slove(a-1,k)<<endl;
		}
    return 0;
    }
